<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="Stylesheet" type="text/css" href="doc.css" />
<title>Working with Workspace Editing Domains</title>
</head>
<body>
<h1><a name="top">Working with Workspace Editing Domains</a></h1>
<p>
Integration with the Eclipse Operation History is provided by a specialization, not exactly
of the <em class="CodeName">TransactionalEditingDomain</em>, but of the
<em class="CodeName">TransactionalCommandStack</em>.  The
<a href="../javadoc/org/eclipse/emf/workspace/WorkspaceEditingDomainFactory.html"><em class="CodeName">WorkspaceEditingDomainFactory</em></a>
initializes a transactional editing domain with an implementation of the
<a href="../javadoc/org/eclipse/emf/workspace/IWorkspaceCommandStack.html"><em class="CodeName">IWorkspaceCommandStack</em></a>
interface.  This command stack delegates to an <em class="CodeName">IOperationHistory</em>
for the execution of EMF <em class="CodeName">Command</em>s.  Transactional editing domains
that use this command stack implementation are casually referred to as
<em>workspace editing domains</em>.
</p>

<blockquote>
	<img src="images/domains.png" alt="Workspace Editing Domain API"/><br/>
	<font size="-2">[<a href="images/domains.svg">as SVG</a>]</font>
</blockquote>

<p>
To use a workspace editing domain, use the factory to create an instance on the operation
history of your choice:
</p>
<pre class="Code">
ResourceSet rset = getResourceSet();  // access some hypothetical resource set
IOperationHistory history = getOperationHistory();  // an operation history

TransactionalEditingDomain domain = <b>WorkspaceEditingDomainFactory</b>.INSTANCE
        .<b>createEditingDomain(rset, history)</b>;

// begin working with the editing domain
</pre>

<p>
Alternatively, register an editing domain on the
<a href="../../../org.eclipse.emf.transaction.doc/references/extension-points/org_eclipse_emf_transaction_editingDomains.html"><em class="CodeName">org.eclipse.emf.transaction.editingDomains</em></a>
extension point using the <em class="CodeName">WorkspaceEditingDomainFactory</em>:
</p>
<pre class="Code">
&lt;extension point="org.eclipse.emf.transaction.editingDomains"&gt;
    &lt;domain> id="org.eclipse.example.MyDomain"
            factory="<b>org.eclipse.emf.workspace.WorkspaceEditingDomainFactory</b>"/&gt;
&lt;/extension&gt;
</pre>
<p>
The above example will result in a workspace editing domain with a default resource set and
a command stack that delegates to the Eclipse Workbench's operation history.  This is what
most applications need.  However, by providing a custom factory extending the default
implementation, the resource set, operation history, and editing domain can all be
customized if necessary.
</p><p>
In all respects, a workspace editing domain and command stack function much as a regular
transactional editing domain and its command stack do.  However, the execution of
<em class="CodeName">Command</em>s on the workspace command stack is only really provided
for compatibility with code (such as in the EMF property sheet) that expects to work with
commands.  Applications are encouraged to <a href="operations.html">execute operations</a>
directly on the operation history, to take full advantage of the undo context and related
capabilities.
</p>

<hr/>

<p>
<a href="https://www.eclipse.org/legal/epl-2.0/">Copyright (c) 2006, 2007 IBM Corporation and others.</a>
</p>
</body>
</html>
